package com.example.mq.producer;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class MyProducer {

    @Autowired
    RabbitTemplate rabbitTemplate;

    public void send(String str) {

        CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());

        //直连
        rabbitTemplate.convertAndSend("DIRECT_EXCHANGE", "zbb.test",
                "this is a direct msg---" + str, correlationId);
       //主题
        rabbitTemplate.convertAndSend("TOPIC_EXCHANGE", "kaifa.zbb.IT",
                "this is a Topic msg---" + str, correlationId);

        //广播
         rabbitTemplate.convertAndSend("FANOUT_EXCHANGE", "",
                "this is a fanout msg---" + str, correlationId);
    }
}